from wt.api_service.api_imp.database_api import DataBaseAPI
from wt.connector.db_manager.db_es_manager import DBElasticSearchManager
from wt.connector.db_manager.db_mongo_manager import DBMongoManager
from wt.connector.db_manager.db_s3_manager import DBS3Manager
from wt.init_param.task_init import TaskInit
from wt.connector.db_manager.db_mysql_manager import DBMysqlManager
from wt.connector.db_manager.db_ftp_manager import FtpExec
from wt.connector.db_manager.db_sftp_manager import SftpExec
from wt.connector.db_manager.db_localFile_manager import LocalFileExec
from wt.connector.db_manager.db_hdfs_manager import HdfsExec
from wt.connector.db_manager.db_oracle12c_manager import DBOracle12cManager
from wt.connector.db_manager.db_oracle11g_manager import DBOracle11gManager
from wt.connector.db_manager.db_dameng_manager import DamengManager
from wt.connector.db_manager.db_highGo_manager import DBHighGoManager
from wt.connector.db_manager.db_starRocks_manager import DBstarRocksManager
from wt.connector.db_manager.db_tidb_manager import DBTidbManager
from wt.connector.db_manager.db_openGauss_manager import DBopenGaussManager
from wt.connector.db_manager.db_psql_manager import Create03PsqlData
from wt.connector.db_manager.db_informix_manager import Create06InformixData
from wt.connector.db_manager.db_sqls_manager import Create04SqlsData
from wt.connector.db_manager.db_doris_manager import DBDorisManger
from wt.connector.db_manager.db_saphana_manager import DBSapHanaManager
from wt.connector.db_manager.db_s3_redshift_manager import DBS3RedshiftManager
from wt.connector.db_manager.db_selectdb_manager import SelectDBManager
from wt.untils.common_until import CommonUntil


class DictDataManagerMethod(TaskInit):
    def __init__(self):
        super().__init__()
        res_db_log = open(self.res_db_log, 'wb+', buffering=0)
        self.db_api = DataBaseAPI(res_db_log)
        self.until = CommonUntil(res_db_log)
        self.mysql_manager = DBMysqlManager()
        self.ftp_manager = FtpExec()
        self.localFile_manager = LocalFileExec()
        self.sftp_manager = SftpExec()
        self.hdfs_manager = HdfsExec()
        self.oracle12c_manager = DBOracle12cManager()
        self.oracle11g_manager = DBOracle11gManager()
        self.dameng_manager = DamengManager()
        self.highGo_manager = DBHighGoManager()
        self.informix_manager = Create06InformixData()
        self.starRocks_manager = DBstarRocksManager()
        self.tidb_manager = DBTidbManager()
        self.openGauss_manager = DBopenGaussManager()
        self.pgsql_manager = Create03PsqlData()
        self.db_sqls_manager = Create04SqlsData()
        self.s3redshift_manager = DBS3RedshiftManager()
        self.doris_v1_manager = DBDorisManger()
        self.doris_v2_manager = DBDorisManger(2)
        self.s3_manager = DBS3Manager()
        self.mongo_manager = DBMongoManager()
        self.es_manager = DBElasticSearchManager()
        self.hana_manager = DBSapHanaManager()
        self.selectdb_manager = SelectDBManager()

    def get_local_param(self):
        dict_param={}
        dict_param["create_db_data"] = self.create_db_data
        dict_param["db_api"] = self.db_api
        dict_param["until"] = self.until

        return dict_param

    def get_db_manager_method(self):
        db_managers = {
            "JDBC-Mysql": self.mysql_manager,
            "MySQL-CDC": self.mysql_manager,
            "JDBC-Informix": self.informix_manager,
            "Informix-CDC": self.informix_manager,
            "JDBC-Postgres": self.pgsql_manager,
            "Postgres-CDC": self.pgsql_manager,
            "JDBC-OpenGauss": self.openGauss_manager,
            "OpenGauss-CDC": self.openGauss_manager,
            "StarRocks": self.starRocks_manager,
            "JDBC-SQLServer": self.db_sqls_manager,
            "SqlServer-CDC": self.db_sqls_manager,
            "JDBC-Highgo": self.highGo_manager,
            "Highgo-CDC": self.highGo_manager,
            "JDBC-Oracle11g": self.oracle11g_manager,
            "Oracle11g-CDC": self.oracle11g_manager,
            "JDBC-Oracle12c": self.oracle12c_manager,
            "Oracle12c-CDC": self.oracle12c_manager,
            "DorisV1": self.doris_v1_manager,
            "DorisV2": self.doris_v2_manager,
            "MongoDB": self.mongo_manager,
            "ElasticSearch": self.es_manager,
            "Dameng-CDC": self.dameng_manager,
            "JDBC-DAMENG": self.dameng_manager,
            "JDBC-TiDB": self.tidb_manager,
            "JDBC-SapHana": self.hana_manager,
            "S3-Redshift": self.s3redshift_manager,
            "SelectDBCloud": self.selectdb_manager,
        }
        return db_managers

    def update_table_data_method(self):
        update_table_data = {
            "JDBC-Mysql": self.mysql_manager.execute_update_data,
            "MySQL-CDC": self.mysql_manager.execute_update_data,
            "JDBC-Postgres": self.pgsql_manager.execute_update_data,
            "Postgres-CDC": self.pgsql_manager.execute_update_data,
            "JDBC-SQLServer": self.db_sqls_manager.execute_update_data,
            "SqlServer-CDC": self.db_sqls_manager.execute_update_data,
            "JDBC-Oracle11g": self.oracle11g_manager.execute_update_data,
            "Oracle11g-CDC": self.oracle11g_manager.execute_update_data,
            "Informix-CDC": self.informix_manager.execute_update_data,
            "JDBC-Informix": self.informix_manager.execute_update_data,
            "Dameng-CDC": self.dameng_manager.execute_update_data,
            "JDBC-DAMENG": self.dameng_manager.execute_update_data,
            "JDBC-Highgo": self.highGo_manager.execute_update_data,
            "Highgo-CDC": self.highGo_manager.execute_update_data,
        }
        return update_table_data
    def get_table_deleted_method(self):
        deleted_generators = {
            "JDBC-Mysql": self.mysql_manager.execute_deleted_data,
            "MySQL-CDC": self.mysql_manager.execute_deleted_data,
            "JDBC-Postgres": self.pgsql_manager.execute_deleted_data,
            "Postgres-CDC": self.pgsql_manager.execute_deleted_data,
            "JDBC-SQLServer": self.db_sqls_manager.execute_deleted_data,
            "SqlServer-CDC": self.db_sqls_manager.execute_deleted_data,
            "JDBC-Oracle11g": self.oracle11g_manager.execute_deleted_data,
            "Oracle11g-CDC": self.oracle11g_manager.execute_deleted_data,
            "Informix-CDC": self.informix_manager.execute_deleted_data,
            "JDBC-Informix": self.informix_manager.execute_deleted_data,
            "Dameng-CDC": self.dameng_manager.execute_deleted_data,
            "JDBC-DAMENG": self.dameng_manager.execute_deleted_data,
            "JDBC-Highgo": self.highGo_manager.execute_deleted_data,
            "Highgo-CDC": self.highGo_manager.execute_deleted_data
        }
        return deleted_generators

    def get_table_10_line(self):
        table_10_line = {
            "JDBC-Mysql": self.mysql_manager.get_db_data,
            "MySQL-CDC": self.mysql_manager.get_db_data,
            "JDBC-Postgres": self.pgsql_manager.get_db_data,
            "Postgres-CDC": self.pgsql_manager.get_db_data,
            "JDBC-SQLServer": self.db_sqls_manager.get_db_data,
            "SqlServer-CDC": self.db_sqls_manager.get_db_data,
            "JDBC-Oracle11g": self.oracle11g_manager.get_db_data,
            "Oracle11g-CDC": self.oracle11g_manager.get_db_data,
            "Dameng-CDC": self.dameng_manager.get_db_data,
            "JDBC-DAMENG": self.dameng_manager.get_db_data,
            "JDBC-Highgo": self.highGo_manager.get_db_data,
            "Highgo-CDC": self.highGo_manager.get_db_data,
            "JDBC-TiDB": self.tidb_manager.get_db_data,
            "DorisV1": self.doris_v1_manager.get_db_data,
            "DorisV2": self.doris_v2_manager.get_db_data,
            "StarRocks": self.starRocks_manager.get_db_data,
            "JDBC-SapHana": self.hana_manager.get_db_data,
            "Informix-CDC": self.informix_manager.get_db_data,
            "JDBC-Informix": self.informix_manager.get_db_data,
        }
        return table_10_line
    def get_file_manager_method(self):
        file_manager = {
            "FtpFile": self.ftp_manager,
            "SftpFile": self.sftp_manager,
            "LocalFileExec": self.localFile_manager,
            "S3File": self.s3_manager,
            "HdfsExec": self.hdfs_manager
        }
        return file_manager

    def get_table_dml_method(self):
        table_dml_generators = {
            "JDBC-Mysql": self.mysql_manager.generate_dml_sql,
            "MySQL-CDC": self.mysql_manager.generate_dml_sql,
            "JDBC-Informix": self.informix_manager.generate_dml_sql,
            "Informix-CDC": self.informix_manager.generate_dml_sql,
            "JDBC-Postgres": self.pgsql_manager.generate_dml_sql,
            "Postgres-CDC": self.pgsql_manager.generate_dml_sql,
            "JDBC-SQLServer": self.db_sqls_manager.generate_dml_sql,
            "SqlServer-CDC": self.db_sqls_manager.generate_dml_sql,
            "JDBC-Oracle11g": self.oracle11g_manager.generate_dml_sql,
            "Oracle11g-CDC": self.oracle11g_manager.generate_dml_sql,
            "Dameng-CDC": self.dameng_manager.generate_dml_sql,
            "JDBC-DAMENG": self.dameng_manager.generate_dml_sql,
            "JDBC-Highgo": self.highGo_manager.define_dml,
            "Highgo-CDC": self.highGo_manager.define_dml,
        }
        return table_dml_generators

    def get_db_create_method(self):
        ddl_generators = {
            "JDBC-Mysql": self.mysql_manager.generate_create_ddl,
            "MySQL-CDC": self.mysql_manager.generate_create_ddl,
            "JDBC-Informix": self.informix_manager.define_ddl,
            "Informix-CDC": self.informix_manager.define_ddl,
            "JDBC-Postgres": self.pgsql_manager.define_ddl,
            "Postgres-CDC": self.pgsql_manager.define_ddl,
            "JDBC-OpenGauss": self.openGauss_manager.define_ddl,
            "OpenGauss-CDC": self.openGauss_manager.define_ddl,
            "JDBC-Tidb": self.tidb_manager.generate_create_ddl,
            "StarRocks": self.starRocks_manager.generate_create_ddl,
            "JDBC-SQLServer": self.db_sqls_manager.define_ddl,
            "SqlServer-CDC": self.db_sqls_manager.define_ddl,
            "JDBC-Highgo": self.highGo_manager.define_ddl,
            "Highgo-CDC": self.highGo_manager.define_ddl,
            "JDBC-Oracle11g": self.oracle11g_manager.define_ddl,
            "Oracle11g-CDC": self.oracle11g_manager.define_ddl,
            "JDBC-Oracle12c": self.oracle12c_manager.define_ddl,
            "Oracle12c-CDC": self.oracle12c_manager.define_ddl,
            "DorisV1": self.doris_v1_manager.generate_create_ddl,
            "DorisV2": self.doris_v2_manager.generate_create_ddl,
            "MongoDB": self.mongo_manager.generate_create_ddl,
            "ElasticSearch": self.es_manager.generate_create_ddl,
            "Dameng-CDC": self.dameng_manager.define_ddl,
            "JDBC-DAMENG": self.dameng_manager.define_ddl
        }

        file_generators = {
            "FtpFile": self.ftp_manager.generate_file,
            "SftpFile": self.sftp_manager.generate_file,
            "LocalFile": self.localFile_manager.generate_file,
            "S3File": self.s3_manager.generate_file
        }

        file_upload = {
            "FtpFile": self.ftp_manager.upload_file,
            "SftpFile": self.sftp_manager.upload_file,
            "LocalFile": "",
            "S3File": self.s3_manager.upload_file
        }
        return ddl_generators, file_generators, file_upload

    def get_db_exec_method(self):
        db_exec = {
            "JDBC-Mysql": self.mysql_manager.exec_sql,
            "MySQL-CDC": self.mysql_manager.exec_sql,
            "JDBC-Informix": self.informix_manager.exec_informix_sql,
            "Informix-CDC": self.informix_manager.exec_informix_sql,
            "JDBC-Postgres": self.pgsql_manager.exec_psql_sql,
            "Postgres-CDC": self.pgsql_manager.exec_psql_sql,
            "JDBC-OpenGauss": self.openGauss_manager.exec_openGauss_db,
            "OpenGauss-CDC": self.openGauss_manager.exec_openGauss_db,
            "JDBC-Tidb": self.tidb_manager.exec_tidb_sql,
            "StarRocks": self.starRocks_manager.exec_starrocks_sql,
            "JDBC-SQLServer": self.db_sqls_manager.exec_sqlserver_sql,
            "SqlServer-CDC": self.db_sqls_manager.exec_sqlserver_sql,
            "JDBC-Highgo": self.highGo_manager.exec_highGo_sql,
            "Highgo-CDC": self.highGo_manager.exec_highGo_sql,
            "JDBC-Oracle11g": self.oracle11g_manager.exec_oracle11g_sql,
            "Oracle11g-CDC": self.oracle11g_manager.exec_oracle11g_sql,
            "JDBC-Oracle12c": self.oracle12c_manager.exec_oracle12c_sql,
            "Oracle12c-CDC": self.oracle12c_manager.exec_oracle12c_sql,
            "DorisV1": self.doris_v1_manager.exec_doris_sql,
            "DorisV2": self.doris_v2_manager.exec_doris_sql,
            "MongoDB": self.mongo_manager.exec_mongodb_sql,
            "ElasticSearch": self.es_manager.exec_es_sql,
            "Dameng-CDC": self.dameng_manager.exec_dameng_sql,
            "JDBC-DAMENG": self.dameng_manager.exec_dameng_sql,
            "SelectDBCloud": self.selectdb_manager.exec_selectdb_sql,
        }
        return db_exec
